package com.ruoyi.user.controller.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SpffVideos;
import com.ruoyi.user.service.IVideoRecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 视频推荐Controller
 * 
 * @author xjj
 * @date 2025-09-23
 */
@RestController
@RequestMapping("/userApi/videos")
public class UVideoRecommendController extends BaseController
{
    @Autowired
    private IVideoRecommendService videoRecommendService;

    /**
     * 个性化推荐视频
     * 基于用户历史观看记录推荐相似视频
     */
    @GetMapping("/recommend")
    public TableDataInfo recommend(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize)
    {
        Long userId = SecurityUtils.getUserId();
        startPage();
        List<SpffVideos> list = videoRecommendService.getPersonalizedRecommend(userId, pageNum, pageSize);
        return getDataTable(list);
    }

    /**
     * 热门视频榜单
     * 按播放量、点赞数等热度指标排序
     */
    @GetMapping("/hotlist")
    public TableDataInfo hotlist(
            @RequestParam(defaultValue = "global") String type,
            @RequestParam(required = false) Long categoryId,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize)
    {
        startPage();
        List<SpffVideos> list = videoRecommendService.getHotVideos(type, categoryId, pageNum, pageSize);
        return getDataTable(list);
    }

    /**
     * 附近的视频
     * 基于地理位置推荐附近的视频
     */
    @GetMapping("/nearby")
    public TableDataInfo nearby(
            @RequestParam BigDecimal latitude,
            @RequestParam BigDecimal longitude,
            @RequestParam(defaultValue = "10") Integer radius,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize)
    {
        startPage();
        List<SpffVideos> list = videoRecommendService.getNearbyVideos(latitude, longitude, radius, pageNum, pageSize);
        return getDataTable(list);
    }

    /**
     * 最新视频
     * 按发布时间倒序排列
     */
    @GetMapping("/latest")
    public TableDataInfo latest(
            @RequestParam(required = false) Long categoryId,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize)
    {
        startPage();
        List<SpffVideos> list = videoRecommendService.getLatestVideos(categoryId, pageNum, pageSize);
        return getDataTable(list);
    }

    /**
     * 随机推荐视频
     * 随机获取一些视频，用于冷启动或增加内容多样性
     */
    @GetMapping("/random")
    public TableDataInfo random(
            @RequestParam(defaultValue = "10") Integer size)
    {
        List<SpffVideos> list = videoRecommendService.getRandomVideos(size);
        return getDataTable(list);
    }
}
